#include "interface.h"
#include <QtGui\QGridLayout>
#include <QtGui\QLabel>
#include <QtGui\QGroupBox>

GraphicsOptionDialog::GraphicsOptionDialog(QWidget* parent /*= NULL*/) : QDialog(parent)
{
  setWindowTitle("Graphics parameters");
  drawPlanetsCheckBox = new QCheckBox("Draw planets", this);
  drawPlanetsCheckBox->setCheckState(Qt::Checked);
  connect(drawPlanetsCheckBox, SIGNAL(stateChanged(int)), this, SLOT(objectEdit(int)));

  drawTrajectoriesCheckBox = new QCheckBox("Draw trajectories", this);
  drawTrajectoriesCheckBox->setCheckState(Qt::Checked);
  connect(drawTrajectoriesCheckBox, SIGNAL(stateChanged(int)), this, SLOT(trajectoryEdit(int)));

  drawCaptionsCheckBox = new QCheckBox("Draw captions", this);
  drawCaptionsCheckBox->setCheckState(Qt::Checked);
  connect(drawCaptionsCheckBox, SIGNAL(stateChanged(int)), this, SLOT(captionEdit(int)));

  animationSpeedEditBox = new QSpinBox(this);
  animationSpeedEditBox->setValue(1);
  connect(animationSpeedEditBox, SIGNAL(valueChanged(int)), this, SLOT(speedEdit(int)));

  QGridLayout* pLayout = new QGridLayout();
  pLayout->addWidget(drawPlanetsCheckBox, 0, 0, 1, 2);
  pLayout->addWidget(drawTrajectoriesCheckBox, 1, 0, 1, 2);
  pLayout->addWidget(drawCaptionsCheckBox, 2, 0, 1, 2);
  
  QGroupBox* animSpeedGroup = new QGroupBox("Animation speed", this);
  QGridLayout* animSpeedLayout = new QGridLayout();
  animSpeedLayout->addWidget(animationSpeedEditBox, 0, 0, 1, 1);
  QLabel* timesLabel = new QLabel("X", this);
  animSpeedLayout->addWidget(timesLabel, 0, 1, 1, 1);
  animSpeedGroup->setLayout(animSpeedLayout);

  pLayout->addWidget(animSpeedGroup, 3, 0, 1, 2);
  setLayout(pLayout);

}

void GraphicsOptionDialog::speedEdit(int mult)
{
  if (mult <= 0)
  {
    animationSpeedEditBox->setValue(1);
    emit changeAnimationSpeed(1);
  }
  else
    emit changeAnimationSpeed(mult);
}

void GraphicsOptionDialog::objectEdit(int drawFlag)
{
  emit changeObjects(drawFlag);
}

void GraphicsOptionDialog::trajectoryEdit(int drawFlag)
{
  emit changeTrajectories(drawFlag);
}

void GraphicsOptionDialog::captionEdit(int drawFlag)
{
  emit changeCaptions(drawFlag);
}

